# coding=utf-8

import pygame
import pygame_gui

pygame.init()

# 创建一个窗口
window_surface = pygame.display.set_mode((800, 600))

# 创建一个包含字体设置的主题文件
theme = {
    "text_box": {
        "font":
        { "regular_path": pygame.font.match_font('Microsoft Yahei'),
        "size": "48"
        }
    }
}

print(str(theme))
with open("mytheme.json", "w") as f:
    f.write(str(theme).replace("'", '"'))
#    pass
#exit(0)

# 创建一个 GUI 管理器，并指定主题文件
manager = pygame_gui.UIManager((800, 600), "mytheme.json", starting_language='zh')

# 创建一个文本框
text_box = pygame_gui.elements.UITextBox(
    '你好, Pygame GUI!',
    relative_rect=pygame.Rect((350, 275), (400, 300)),
    manager=manager,
    object_id='#welcome_text',
    visible=True
)

# 主循环
running = True
while running:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False

        manager.process_events(event)

    manager.update(0.01)

    window_surface.fill((255, 255, 255))
    manager.draw_ui(window_surface)

    pygame.display.update()

pygame.quit()
